package io.renren.modules.task.controller;

/**
 * @Author: CaiXiang
 * @Date: 2019/5/31 14:52
 * @Version 1.0
 * @Description:
 */


import io.renren.common.utils.R;
import io.renren.modules.sys.controller.AbstractController;
import io.renren.modules.sys.dao.SysLogDao;
import io.renren.modules.sys.service.SysLogService;
import io.renren.modules.task.entity.KeyValuePair;
import io.renren.modules.task.model.SysLogEntityVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * 日志查询
 *
 * @author 蔡翔 939387484@qq.com
 * <p>
 * 更新记录：
 * 蔡翔    上次登入日志查询                               2019-05-31
 */
@Api(description = "日志查询接口")
@RestController
@RequestMapping("/LogQuery")
public class LogQueryController extends AbstractController {
    @Autowired
    private SysLogService sysLogService;

    @Autowired
    private SysLogDao sysLogDao;

    @ApiOperation(value = "查询上一次登录", notes = "查询上一次登录")
    @GetMapping("/queryLastLogin")
    public R queryLastLogin() {
        String username = getUser().getUsername();
        List<SysLogEntityVo> logList = sysLogDao.queryLastLogin(username);
        SysLogEntityVo sysLogEntityVo = logList.get(1);

        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("createDate", sysLogEntityVo.getCreateDate().toString());
        hashMap.put("username", sysLogEntityVo.getUsername());
        hashMap.put("ip", sysLogEntityVo.getIp());

        //1.
        List result = new ArrayList();
        result.add(sysLogEntityVo);

        //2.   1,2 都可以
        List<SysLogEntityVo> list = new ArrayList<SysLogEntityVo>();
        list.add(sysLogEntityVo);

        return R.ok().put("result", result);
    }
}
